<?php
ob_start();

include_once 'inc/global.php';
include_once 'inc/queryhelper.php';
//define('TID','666');

if (strlen(session_id()) < 1)
    session_start();

if (!isset($_SESSION['tid']))
    $_SESSION['tid'] = '';

$tid = $_GET['t'];// $_SESSION['tid'];
$tablename = $tables[$tid]['t'];

$id = intval($_REQUEST['id']);

include 'inc/conn.php';

switch ($tid) {
    case 1: //city
        $city = $_REQUEST['city'];
        $sql = "update $tablename set city='$city' where id=$id";
        break;
    case 2: //partner
        $partnername    = $_REQUEST['partnername'];
        $street1        = $_REQUEST['street1'];
        $city           = $_REQUEST['city'];
        $zip            = $_REQUEST['zip'];
        $phone1         = $_REQUEST['phone1'];
        $email          = $_REQUEST['email'];
        //$cityname       = getFieldValue("ats_city", "city", "id", "'$city'");
        $cityname       = $_REQUEST['cityname'];
        
        $sql = "update ats_partners set 
                    partnername='$partnername', 
                    street1='$street1', 
                    city='$city', 
                    cityname='$cityname',
                    zipcode='$zip', 
                    phone1='$phone1', 
                    email='$email' 
                where id=$id";
        break;
    case 3:  //package
        $title = $_REQUEST['title'];
        $short_title = $_REQUEST['short_title'];
        $cityid = $_REQUEST['cityid'];
        $monthstart = $_REQUEST['monthstart'];
        $yearstart = $_REQUEST['yearstart'];
        $monthend = $_REQUEST['monthend'];
        $yearend = $_REQUEST['yearend'];
        $currency = $_REQUEST['currency'];
        $currency = $_REQUEST['currency'];
        $pricestart = $_REQUEST['pricestart'];
        $dest_id = $_REQUEST['dest_id'];
        $cat_id = $_REQUEST['cat_id'];
        $isspecialoffer = $_REQUEST['isspecialoffer'];
        $ov_title = $_REQUEST['ov_title'];
        $ov_period = $_REQUEST['ov_period'];
        $ov_bonus = $_REQUEST['ov_bonus'];
        $ov_highlight = $_REQUEST['ov_highlight'];
        $ov_notice = $_REQUEST['ov_notice'];
        $da_pricelabel = $_REQUEST['da_pricelabel'];
        $da_depdates = $_REQUEST['da_depdates'];
        $da_extraprice = $_REQUEST['da_extraprice'];
        $da_pricetable = $_REQUEST['da_pricetable'];
        $tr_embassyid = $_REQUEST['tr_embassyid'];
//        $tr_embaddress = $_REQUEST['tr_embaddress'];
//        $tr_embphone = $_REQUEST['tr_embphone'];
//        $tr_embfax = $_REQUEST['tr_embfax'];
//        $tr_requirement = $_REQUEST['tr_requirement'];
//        $tr_notes = $_REQUEST['tr_notes'];
//        $tr_visaprices = $_REQUEST['tr_visaprices'];
        $pdf_attachment = $_REQUEST['pdf_attachment'];
        $featured = $_REQUEST['featured'];
        $imagedisplay = $_REQUEST['imagedisplay'];
        
        if ($tr_embassyid == '') $tr_embassyid = -1;
        $sql = "UPDATE 
                  ats_package  
                SET 
                  title = '$title',
                  monthstart = '$monthstart',
                  monthend = '$monthend',
                  yearstart = '$yearstart',
                  yearend = '$yearend',
                  currency = '$currency',
                  pricestart = '$pricestart',
                  dest_id = '$dest_id',
                  cat_id = '$cat_id',
                  isspecialoffer = '$isspecialoffer',
                  ov_title = '$ov_title',
                  ov_period = '$ov_period',
                  ov_bonus = '$ov_bonus',
                  ov_highlight = '$ov_highlight',
                  ov_notice = '$ov_notice',
                  da_depdate = '$da_depdates',
                  da_pricelabel = '$da_pricelabel',
                  da_extraprice = '$da_extraprice',
                  da_pricetable = '$da_pricetable',
                  tr_embassyid = '$tr_embassyid',
                  featured = 0,
                  cityid = '$cityid',
                  short_title = '$short_title',
                  pdf_attachment = '$pdf_attachment',
                  featured='$featured',
                  image='$imagedisplay'
                WHERE 
                  id = $id";
        
        break;
    case 5: //reply contact us
        break;
    case 6: //package prices
        $type = $_REQUEST['type'];
        $curr = $_REQUEST['currency'];
        //$price = $_REQUEST['price'];
        $pricetext = $_REQUEST['pricetext'];
        
        $sql = "update $tablename set type='$type',currency='$curr',pricetext='$pricetext' where id=$id";
        break;
    case 7:  //itinerary
        $detail = $_REQUEST['detail'];
        $sql = "update ats_itinerary set detail='$detail' where id=$id";
        
        break;
    case 8:  //users
        $username = $_REQUEST['username'];
        $password = $_REQUEST['password'];
        $email = $_REQUEST['email'];
        $sql = "update ats_users set username='$username', password=password('$password'),email='$email' where id=$id";
        
        break;
    case 9: //reply partner contact
        break;
    case 10:  //package category
        $package = $_REQUEST['package'];
        $description = $_REQUEST['description'];
        $sql = "update $tablename set package='$package', description='$description' where id=$id";
        
        break;
    case 11:  //embassy
        $embassy = $_REQUEST['embassy'];
        $address = $_REQUEST['address'];
        $phone = $_REQUEST['phone'];
        $fax = $_REQUEST['fax'];
        $requirement = $_REQUEST['requirement'];
        $notes = $_REQUEST['notes'];
        $visaprices = $_REQUEST['visaprices'];

        $sql = "update ats_embassy set embassy='$embassy', address='$address', phone='$phone', fax='$fax', requirement='$requirement', notes='$notes', visaprices='$visaprices'
            where id=$id";
        
        break;
    case 12:
        $tablabel = $_REQUEST['tablabel'];
        $address1 = $_REQUEST['address1'];
        $address2 = $_REQUEST['address2'];
        $region = $_REQUEST['region'];
        $city = $_REQUEST['city'];      
        $country = $_REQUEST['country'];
        $phone1 = $_REQUEST['phone1'];
        $phone2 = $_REQUEST['phone2'];
        $fax1 = $_REQUEST['fax'];
        $email = $_REQUEST['email'];
        
        $sql = "update ats_branch set tablabel='$tablabel',address1='$address1',address2='$address2',region='$region',city='$city',country='$country',phone1='$phone1',phone2='$phone2',fax1='$fax1',email='$email'
                WHERE id=$id";
        break;
    default:
        $firstname = $_REQUEST['firstname'];
        $lastname = $_REQUEST['lastname'];
        $phone = $_REQUEST['phone'];
        $email = $_REQUEST['email'];

        $sql = "update users set firstname='$firstname',lastname='$lastname',phone='$phone',email='$email' where id=$id";
        break;
}

$result = @mysql_query($sql)
    or die(json_encode(array('msg' => $sql)));

if ($result) {
    echo json_encode(array('success' => true));
} else {
    echo json_encode(array('msg' => 'Some errors occured.'));
}
ob_end_flush();

?>